<?php

namespace Home\Controller;

class UserController extends BaseController {

    private $model = null;

    function __construct() {
        parent::__construct();
        if (!session('userinfo')) {
            $this->redirect('/Account/login');
        }
        $this->model = D('User');
    }

    function index() {
        $this->menu = 1;
        $this->display();
    }

    function AlertMyPwd() {
        if (IS_POST) {
            $oldPassword = I('post.pwdOld', '', 'trim');
            $email = parent::$email;
            $where = array('email' => $email);
            $info = D('Account')->getOneUser($where);
            if ($info['password'] != md5($info['email'] . $oldPassword)) {
                $this->error('原始密码错误！');
            }
            $password = I('post.pwd', '', 'trim');
            $data['password'] = md5($info['email'] . $password);
            if (D('Account')->modifyPassword($email, $data) !== false) {
                $this->success('修改成功！');
            } else {
                $this->error('修改失败！');
            }
            print_r(I('post.'));
            exit;
        } else {
            $this->display();
        }
    }

}
